package com.ciban.smarthome.module.ui.adapter;

import java.util.ArrayList;

import com.ciban.smarthome.R;
import com.ciban.smarthome.common.utils.ImgUtils;
import com.ciban.smarthome.module.entity.Equip_Curtain;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CurtainListLvAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<Equip_Curtain> list;

	public CurtainListLvAdapter(Context context, ArrayList<Equip_Curtain> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = View.inflate(context,
					R.layout.listitem_equip_curtain, null);
			holder = new ViewHolder();
			holder.iv_icon = (ImageView) convertView
					.findViewById(R.id.curtain_pop_icon);
			holder.tv_desc = (TextView) convertView
					.findViewById(R.id.curtain_pop_name);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		Equip_Curtain info = list.get(position);
		// holder.iv_icon.setImageResource(Integer.parseInt(info.getIcon_path()));
		holder.iv_icon.setImageBitmap(ImgUtils.getImageFromAssetsFile(context,
				info.getIcon_path()));
		holder.tv_desc.setText(info.getName());

		return convertView;
	}

	static class ViewHolder {
		ImageView iv_icon;
		TextView tv_desc;
	}

}
